<template>
	<div>
		<div class="order-btn-container">
			<div class="c-btn big black" @click="backPopshow = true">申请二次报修</div>
			<div class="c-btn big reverse" @click="confirmPopshow = true"
			:class="{disabled: uploading}">确认</div>
			<pop :popshow="backPopshow"
			:popstyle="{width:'8.5rem'}">
				<txtpop title="退回原因"
				:maxlength="200"
				placeholder="请输入退回原因"
				@cancel="cancelBack"
				@send="sendBack"></txtpop>
			</pop>
			<pop :popshow="confirmPopshow"
			:popstyle="{width:'8.5rem'}">
				<txtpop title="评价"
				:maxlength="200"
				placeholder="对修理结果满意吗？"
				@cancel="cancelConfirm"
				@send="sendConfirm"></txtpop>
			</pop>
		</div>
	</div>
</template>
<script>
	import pop from '../Pop.vue'
	import txtpop from '../TxtPop.vue'
	import {myAlert, myHttp, nextPage} from '../assets/js/utils.js'
	export default{
		name: 'RepairmanConfirm',
		data(){
			return {
				backPopshow: false,
				confirmPopshow: false,
				uploading: false
			}
		},
		methods:{
			cancelBack(){
				this.backPopshow = false;
			},
			sendBack(txt){
				if(this.uploading) return;
				if(!txt) {
					myAlert.small('请输入退回原因');
					return;
				}
				this.backPopshow = false;
				let fm = new FormData();
				fm.append('lastRepairId', this.$route.params.id);
				fm.append('userId', localStorage.getItem('userId'));
				fm.append('repairReason', txt);
				fm.append('licenseCode', 'E2ECBC62529F0D090EA369022622F74B');
				// fm.append('mediaId', '');
				// fm.append('imageFiles', '');
				myHttp('addSecondRepair.do', fm, () => {
					this.uploading = true
				}).then((r) => {
					if(!r.failed){
						myAlert.small('退回成功').then(() => {
							this.$router.push({path:'/repair/list/user'});
						})
					} else this.uploading = false;
				})
			},
			cancelConfirm(){
				this.confirmPopshow = false;
			},
			sendConfirm(txt){
				if(this.uploading) return;
				this.confirmPopshow = false;
				myHttp('addEvaluate.do',{
					repairId: this.$route.params.id,
					userId: localStorage.getItem('userId'),
					evaluaDesc: txt
				}, () => {
					this.uploading = true
				}).then((r) => {
					if(!r.failed){
						myAlert.small('评价成功').then(() => {
							this.$router.push({path:'/repair/list/user'});
						})
					} else this.uploading = false;
				})
			}
		},
		props: ['id','userId'],
		components: {pop, txtpop}
	}
</script>